﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection;
using StyleMVVM.Validation;

namespace ExampleApp.ViewModels.Validation
{
	[Export(typeof(IValidationMethodProvider<BasicValidationViewModel>))]
	public class MethodValidationForBVVM : IValidationMethodProvider<BasicValidationViewModel>
	{
		public void ProvideRules(IValidationMethodCollection<BasicValidationViewModel> methodCollection)
		{
			methodCollection.AddRule(IanJohnsonRule).
				MonitorProperty(x => x.FirstName).MonitorProperty(x => x.LastName).MonitorProperty(x => x.MiddleName);
		}

		private void IanJohnsonRule(IRuleExecutionContext<BasicValidationViewModel> obj)
		{
			if (string.Compare(obj.ValidationObject.FirstName, "Ian", StringComparison.CurrentCultureIgnoreCase) == 0 &&
				 string.Compare(obj.ValidationObject.MiddleName, "Phillip", StringComparison.CurrentCultureIgnoreCase) == 0 &&
				 string.Compare(obj.ValidationObject.LastName, "Johnson", StringComparison.CurrentCultureIgnoreCase) == 0)
			{
				obj.AddError(x => x.FirstName, "Your first name can't be Ian when your last name is Johnson");
				obj.AddError(x => x.MiddleName,"Your middle name can't be Ian Phillip Johnson ... I am!");
				obj.AddError(x => x.LastName, "Your first name can't be Ian when your last name is Johnson");

				obj.Message = "You can not be Ian Phillip Johnson ... Identity Thief!";
			}
		}
	}
}
